package cn.com.recycleviewdemo;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.widget.ImageView;

import java.util.ArrayList;
import java.util.List;

import cn.com.recycleviewdemo.adapter.RecyclerGridViewAdapter;
import cn.com.recycleviewdemo.decoration.ItemOffsetDecoration;

public class MainActivity extends AppCompatActivity {

    private  RecyclerGridViewAdapter adapter;

    private List<String> list=new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        list.add("http://pic4.nipic.com/20091217/3885730_124701000519_2.jpg");
        list.add("http://www.taopic.com/uploads/allimg/140107/234764-14010F0310582.jpg");
        list.add("http://pic49.nipic.com/file/20140927/19617624_230415502002_2.jpg");

        RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
        adapter = new RecyclerGridViewAdapter(list,callback);
        recyclerView.setLayoutManager(new GridLayoutManager(this, 4));
        ItemOffsetDecoration itemDecoration = new ItemOffsetDecoration(this, R.dimen.item_offset);
        recyclerView.addItemDecoration(itemDecoration);
        recyclerView.setAdapter(adapter);

    }

    private RecyclerGridViewAdapter.Callback callback=new RecyclerGridViewAdapter.Callback() {
        @Override
        public void onInserteClick() {
            adapter.notifyItemRemoved(adapter.getItemCount()-1);
            Log.e("MainActivity", "adapter.getItemCount():" + adapter.getItemCount());
            list.add("http://img02.tooopen.com/images/20150507/tooopen_sy_122398133951.jpg");
            adapter.notifyItemInserted(list.size());
        }

        @Override
        public void onDeleteClick(int i) {
            list.remove(0);
            adapter.notifyItemRemoved(0);
        }

        @Override
        public void onZoomInClick(ImageView imageView, List<ImageView> imageGroupList, List<String> urlList) {
            Log.e("MainActivity", "imageGroupList.size():" + imageGroupList.size());
            Log.e("MainActivity", "urlList:" + urlList.size());
        }
    };



}
